package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理接口")
public class DishController {
    @Autowired
    private DishService dishService;

    /**
     * 分页查询菜品信息
     * @param dishPageQueryDTO
     * @return
     */
    @ApiOperation(value = "分页查询菜品信息")
    @GetMapping("/page")
    public Result<PageResult> DishPageQuery(DishPageQueryDTO dishPageQueryDTO){
        log.info("分页查询菜品参数:{}",dishPageQueryDTO);
        PageResult pageResult=dishService.PageQuery(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增菜品
     * @param dishDTO
     * @return
     */
    @ApiOperation(value = "新增菜品")
    @PostMapping
    public Result addDish(@RequestBody DishDTO dishDTO){
        log.info("新增菜品参数:{}",dishDTO);
        dishService.addDish(dishDTO);
        return Result.success();
    }

    /**
     * 起售/停售菜品
     * @param status
     * @param id
     * @return
     */
    @ApiOperation(value = "起售/停售菜品")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status, Long id){
        log.info("起售/停售菜品参数:status={},id={}",status,id);
        dishService.updateStatus(status,id);
        return Result.success();
    }
    @ApiOperation(value = "菜品批量删除")
    @DeleteMapping
    public Result deleteDish(@RequestParam List<Long> ids){
        log.info("菜品批量删除参数:ids={}",ids);
        dishService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改菜品信息
     * @param dishDTO
     * @return
     */
    @ApiOperation(value = "修改菜品信息")
    @PutMapping
    public Result updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDish(dishDTO);
        return Result.success();
    }

    /**
     * 根据id查询菜品信息
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询菜品信息")
    @GetMapping("/{id}")
    public Result<DishVO> getDishById(@PathVariable Long id){
        log.info("根据id查询菜品信息参数:id={}",id);
        DishVO dishVO=dishService.getByIDWithFlavor(id);
        return Result.success(dishVO);
    }

    /**
     * 根据菜品分类id查询菜品
     * @param categoryId
     * @return
     */
    @ApiOperation(value = "根据菜品分类id查询菜品")
    @GetMapping("/list")
    public Result<List<Dish>> getDishByCategoryId(Long categoryId){
        log.info("根据菜品分类id查询菜品参数:categoryId={}",categoryId);
        List<Dish> list=dishService.getByCategoryId(categoryId);
        return Result.success(list);
    }
}
